'use strict';

var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');
var _interopRequireWildcard = require('@babel/runtime/helpers/interopRequireWildcard');
Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require('@babel/runtime/helpers/objectSpread2'));
var _objectWithoutProperties2 = _interopRequireDefault(
  require('@babel/runtime/helpers/objectWithoutProperties'),
);
var _react = _interopRequireWildcard(require('react'));
var _antd = require('antd');
var _useOptions2 = _interopRequireDefault(require('../../../hooks/useOptions'));
var _createField = _interopRequireDefault(require('../../../createField'));
var _excluded = ['children', 'options'];
var Checkbox = function Checkbox(_ref) {
  var children = _ref.children,
    optionsProp = _ref.options,
    rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var _useOptions = (0, _useOptions2.default)(optionsProp),
    options = _useOptions.options;
  (0, _react.useEffect)(
    function () {
      var existed =
        (rest === null || rest === void 0 ? void 0 : rest.value) && options.length
          ? options.some(function (option) {
              var _rest$value;
              return (_rest$value = rest.value) === null || _rest$value === void 0
                ? void 0
                : _rest$value.includes(option.value);
            })
          : false;
      if ((rest === null || rest === void 0 ? void 0 : rest.value) && !existed) {
        var _rest$onChange;
        (_rest$onChange = rest.onChange) === null || _rest$onChange === void 0
          ? void 0
          : _rest$onChange.call(rest, []);
      }
    },
    [options],
  );
  return /*#__PURE__*/ _react.default.createElement(
    _antd.Checkbox.Group,
    (0, _objectSpread2.default)(
      (0, _objectSpread2.default)({}, rest),
      {},
      {
        options: options,
      },
    ),
    children,
  );
};
var _default = (0, _createField.default)(Checkbox);
exports.default = _default;
